<template>
  <view>
    <u-navbar title="选择课程" auto-back fixed placeholder></u-navbar>
    <view class="content">
      <z-paging ref="paging" fixed use-safe-area-placeholder refresher-vibrate refresher-only
			@query="onRefresh" safe-area-inset-bottom show-refresher-when-reload show-refresher-update-time
			style="top: calc(44px + var(--status-bar-height));" @scroll="onScroll">
        <u-gap height="10px" bg-color="#f5f5f5"></u-gap>
        <u-cell v-for="item in dataList" :key="item.id" @click="goItem(item)">
          <view class="cell_title" slot="title">{{ item.name }}</view>
          <view class="cell_label" slot="label">{{ item.clazz }}</view>
          <view class="cell_value" slot="value">
            <u-icon name="arrow-right" color="#999999"></u-icon>
          </view>
        </u-cell>
      </z-paging>
    </view>
  </view>
</template>

<script>
import {
  getSubjectList
} from '@/api/subject'
import mixin from '@/mixin'
export default {
  components: {},
  data() {
    return {
      
    }
  },
  mixins: [mixin],
  created() {
    this.getDataList(true)
  },
  methods: {
    getDataList(isRefresh) {
      const params = {}
      params.current = this.current
      params.siftId = this.$store.getters.username
      getSubjectList(params).then(res => {
        this.$refs.paging.complete()
        this.isRequest = false
        const { code, data } = res
        if(isRefresh) {
          this.dataList = []
        }
        if(code === 200) {
          data.list.forEach(item => {
            this.dataList.push(item)
          })
          this.total = data.total
        }
        if(data.total > this.dataList.length) {
          this.loadMore = 'loadmore'
        }else {
          this.loadMore = 'nomore'
        }
      }).catch(err => {
        this.$refs.paging.complete()
        this.isRequest = false
      })
    },
    goItem(item) {
      uni.navigateTo({
        url: `/teacher/sign/list?id=${item.id}`
      })
    }
  },
  watch: {},

  // 页面周期函数--监听页面加载
  onLoad() {},
  // 页面周期函数--监听页面初次渲染完成
  onReady() {},
  // 页面周期函数--监听页面显示(not-nvue)
  onShow() {},
  // 页面周期函数--监听页面隐藏
  onHide() {},
  // 页面周期函数--监听页面卸载
  onUnload() {},
  // 页面处理函数--监听用户下拉动作
  // onPullDownRefresh() { uni.stopPullDownRefresh(); },
  // 页面处理函数--监听用户上拉触底
  // onReachBottom() {},
  // 页面处理函数--监听页面滚动(not-nvue)
  // onPageScroll(event) {},
  // 页面处理函数--用户点击右上角分享
  // onShareAppMessage(options) {},
} 
</script>

<style lang="scss" scoped>
.cell_title {
  width: calc(100vw - 30px - 16px);
  font-weight: bold;
  font-size: 16px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.cell_label {
  color: #999;
  font-size: 12px;
}
</style>